package com.ruoyi.web.controller.api;

import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.user.vo.LoginVo;
import com.ruoyi.web.domain.user.vo.RegisterVo;
import com.ruoyi.web.domain.user.vo.SubscribeVo;
import com.ruoyi.web.entity.user.response.UserCenterResponse;
import com.ruoyi.web.mapper.ApiUserMapper;
import com.ruoyi.web.service.ApiUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 * 
 * @author ruoyi
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/api/user")
public class ApiUserController extends BaseController
{
    @Autowired
    private ApiUserService apiUserService;

    @Autowired
    private ApiUserMapper apiUserMapper;


    @ApiOperation(value = "根据手机号登录")
    @ApiOperationSupport(author = "有为", order = 1)
    @PostMapping("/login")
    @Log(title = "登录", businessType = BusinessType.INSERT)
    public AjaxResult login(LoginVo loginVo) {
        UserCenterResponse response = apiUserService.login(loginVo);

        return success(response);
    }

    @ApiOperation(value = "注册")
    @ApiOperationSupport(author = "有为", order = 2)
    @PostMapping("/register")
    @Log(title = "注册", businessType = BusinessType.INSERT)
    public AjaxResult register(RegisterVo registerVo) {
        UserCenterResponse res = apiUserService.register(registerVo);

        return success(res);
    }

    @ApiOperation(value = "根据code获取手机号")
    @ApiOperationSupport(author = "有为", order = 3)
    @ApiImplicitParam(name = "code", value = "微信code", required = true)
    @PostMapping("/getPhone")
    @Log(title = "根据code获取手机号", businessType = BusinessType.SELECT)
    public AjaxResult getPhone(String code) {

        WxMaPhoneNumberInfo res = apiUserService.getPhone(code);

        return success(res);
    }

    @ApiOperation(value = "发送订阅消息")
    @ApiOperationSupport(author = "有为", order = 4)
    @PostMapping("/sendSubscribe")
    @Log(title = "发送订阅消息", businessType = BusinessType.INSERT)
    public AjaxResult sendSubscribe(SubscribeVo subscribeVo){

//        apiUserService.sendSubscribe(subscribeVo);


        Long[] userIds = {1L, 2L, 3L};

        return success(apiUserMapper.batchUserList(userIds));

    }


}
